package com.huifaapp.mall.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.huifaapp.mall.R;
import com.huifaapp.mall.bean.HelpcenterBean;

import java.util.List;

/**
 * Created by mac on 2018/1/25.
 */

public class HelpcenterAdapter extends BaseAdapter {
    private ViewHolder viewHolder;
    private Context context;
    private List<HelpcenterBean.DataBean>list;
//    int position;
    //当前Item被点击的位置
    private int currentItem;
    private int a;

    public void setCurrentItem(int currentItem) {
        this.currentItem = currentItem;
    }
    public HelpcenterAdapter(Context context, List<HelpcenterBean.DataBean> list,int currentItem) {
        this.context = context;
        this.list = list;
        this.currentItem=currentItem;
        Log.e("帮助中心adapter",list+"");
    }





    View currentView;

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view= LayoutInflater.from(context).inflate(R.layout.help_center_item,null);
        viewHolder = new ViewHolder(view);
        viewHolder.bt_help.setText(list.get(position).getName());

        if (currentItem == position) {
            Log.e("帮助中心点击取的position选中",position+"");
            //如果被点击，设置当前TextView被选中
            viewHolder.bt_help.setSelected(true);
            viewHolder.bt_help.setBackgroundResource(R.drawable.shape);
        } else {
            Log.e("帮助中心点击取的position未选中",position+"");
            //如果没有被点击，设置当前TextView未被选中
            viewHolder.bt_help.setSelected(false);
            viewHolder.bt_help.setBackgroundResource(R.drawable.shape_button_mm);
        }
        return view;
    }



    public class ViewHolder extends RecyclerView.ViewHolder{


        TextView bt_help;

        public ViewHolder(View itemView) {
            super(itemView);
            bt_help = (TextView) itemView.findViewById(R.id.center_itemhelp);
        }
    }


}
